<?php
class Solution {

    /**
     * @param Integer[] $nums
     * @param Integer $k
     * @return NULL
     */
    function rotate(&$nums, $k) {
        if(empty($nums))
            return [];
        $len = count($nums);
        $k = $k % $len;
        $this->reverse($nums, 0, $len-1);
        $this->reverse($nums, 0, $k-1);
        $this->reverse($nums, $k, $len-1);
    }

    function reverse(&$nums, $start, $end){
        while($start < $end){
            $tmp = $nums[$start];
            $nums[$start] = $nums[$end];
            $nums[$end] = $tmp;
            $start++;
            $end--;
        }
    }
}

